<?php
/*
 * @Descripttion: 
 * @Author: dedeye
 * @Date: 2020-02-25 17:46:18
 * @LastEditors: dedeye
 * @LastEditTime: 2020-02-25 23:42:36
 */

namespace app\http\middleware;

use think\facade\Session;
use app\common\util\Tool;

class AdminLoginCheck
{
    public function handle($request, \Closure $next)
    {
        if(!self::checkLogin()) {
            return redirect('admin/login/index');
        }
        return $next($request);
    }

    private static function checkLogin()
    {
        if(Session::has('admin_id') && Session::has('admin_code')) {
            $code = Tool::opensslEncode(Session::get('admin_id'));
            if($code !== false) {
                if($code == Session::get('admin_code')) {
                    return true;
                }
            }
        }
        return false;
    }
}
